package city.spring.modules.medicalstation.drugsettings.drugsettingsDrugExt.service.impl;

import city.spring.modules.medicalstation.drugsettings.drugsettingsDrugExt.entity.DrugsettingsDrugExtEntity;
import city.spring.modules.medicalstation.drugsettings.drugsettingsDrugExt.repository.DrugsettingsDrugExtRepository;
import city.spring.modules.medicalstation.drugsettings.drugsettingsDrugExt.service.DrugsettingsDrugExtService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：用药设置与药品关联表
 *
 * @author 谢金婷
 * @date 2020-10-15 09:55:17
 */
@CacheConfig(cacheNames = {DrugsettingsDrugExtServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Exception.class)
@Service
public class DrugsettingsDrugExtServiceImpl extends ServiceImpl<DrugsettingsDrugExtRepository, DrugsettingsDrugExtEntity> implements DrugsettingsDrugExtService {

    @Override
    public void saveDrugsettingsDrugExt(DrugsettingsDrugExtEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateDrugsettingsDrugExt(DrugsettingsDrugExtEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        if (!updateById(entity)) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteDrugsettingsDrugExt(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteDrugsettingsDrugExt(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }
}